import { COLLECTIONS, FOOTPRINTS } from "../../config";
import { Event } from "../../utils/interface";
import { observer } from "../../utils/observer";
import { addAddress } from "../cart/cart";
import { Detail } from "../goods_detail/goods_detail";

let shops: Array<any> = [];
let colls: Array<Detail> = [];
let fShops: Array<Detail> = [];
let foos: Array<Detail> = [];

let options = [
  { name: "联系客服", k: "400-618-4000" },
  { name: "意见反馈", k: ">" },
  { name: "关于我们", k: ">" },
];

let pays = [
  {
    name: "全部订单",
    icon: "icon-calendar",
  },
  {
    name: "代付款",
    icon: "icon-guanyu",
  },
  {
    name: "待收货",
    icon: "icon-liuyan1",
  },
  {
    name: "退款/退货",
    icon: "icon-liwuhuodong",
  },
];

let data = {
  shops,
  colls,
  fShops,
  foos,
  pays,
  options,
};
Page({
  data,
  onShow() {
    data = observer(this.data, this);
    this.init();
  },
  init() {
    data.colls = wx.getStorageSync(COLLECTIONS) || [];
    data.foos = wx.getStorageSync(FOOTPRINTS) || [];
    data.fShops = data.colls;
    data.shops = [];
  },
  toColl() {
    wx.navigateTo({
      url: "/pages/collect/collect",
    });
  },
  adminAddress() {
    addAddress();
  },
  tapOption,
  toOrder() {
    wx.navigateTo({
      url: "/pages/order/order",
    });
  },
});
function tapOption(e: Event<{ name: string }>) {
  const name = e.currentTarget.dataset.name;
  switch (name) {
    case "意见反馈":
      wx.navigateTo({
        url: "/pages/feedback/feedback",
      });
      break;
    case "关于我们":
      wx.showToast({
        title: "关于我们",
        duration: 2000,
      });
      break;
  }
}
